<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ include file="/mb/jsp/common.jsp" %>

<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>我的订单</title>
    <style>
        .pbm_date {
            border: none;
        }
        .kindNav>div {
			    width: 100%;
			}
        .kindNav span{
        	width:20%;
        	text-align:center;
        	padding:0;
        }
    </style>
</head>
<body ontouchstart="">
<div class="detailTop pf w100 of">
    <div class="w100 of tc cf f18">
        <span class="pa" style="left: 2px;" onclick="javascript:history.back();"><img src="mb/images/top_back_white.png" style="margin-top: 4px;height: 40px;width: 40px;"/></span>
		     我的订单
    </div>
</div>
<div class="kindNav pf bcf w100 of" style="top:45px;">
    <div class="w100  pr">
       <span  class="kindNavCurrent">全部</span><span>待付款</span><span>待发货</span><span>待收货</span><span>已完成</span>
    </div>
</div>

<div class="container db jz" style="margin-top:89px">

    <div id="container">
		
        <div id="resText"></div><!--resText-->
      
    </div>
      	<div id="loading" class="w100">
            <img src="mb/images/loading.gif" alt="正在加载" class="db jz hauto" style="width: 15px;">
            <div class="w100 tc f10 c9">正在加载</div>
        </div>
         <div id="loadingComplete" class="w100" style="display:none;">
            <div class="w100 tc f12 c9">已加载完所有数据</div>
        </div>

    <section class="w100" style="height: 66px;"></section>
</div>


  	<!--footer-->
<footer id="footer" class="footerTab w100 of pf">
 
</footer>

<script>
    var curpageVal = 1;
    var typeVal = -1;/* 类型， -1:全部 0:已取消 1：待付款 2：待发货 5：待收货 6：已完成 */
    var htmlStr="";
    var total = "";
   //加载新数据
   
   
   
    function getData() {
    	/* console.log("curpage: "+curpageVal); */
    	
        $.ajax({
            url: "PlugServlet",
            data: JSON.stringify({m: 1750, curpage: curpageVal,type:typeVal}),
            type: 'post',
            dataType: 'json',
            contentType: "application/json;charset=utf-8",
            beforeSend: function () {
                showProgressDg();
            },
            success: function (data) {
            	console.log(data);
                if (data.state == 1) {
                
					if(data.list==""||data.list==null){
					 	showToast("暂无数据..");
	                 	return false;
	                 }
                  		 getItemHtml(data);
                    
                   		 total = data.total;
        
                } else {
                    // 其他错误弹出提示
                    showToast(data.info);
                }
            },
            error: function (data) {
                showToast(data.info);
            },
            complete: function () {
                closeProgressDg();
            }
        });
        	
       return total;
    }


  function getItemHtml(data)
    {
    	$.each(data.list, function(index, obj) 
    		
    	{
	        var projectimage = obj.projectimage.split(';')[0];
	        
          htmlStr +='<section class="bcf w95 jz of mgt10"  onclick="toOrderDetail('+obj.orderid+');">'
						+'<div class="w95 jz b-b f13 flexBox" style="line-height:40px;">'
							+'<div class="df">'
								+'<img src="mb/images/myOrder.png" style="height:16px"><p class="c3 mgl10">'+obj.companyname+'</p>'
							+'</div>'
							+'<p class="orange2">'+obj.stateAbout+'</p>'
						+'</div>'
						+'<div class="w95 jz df pdt10 pdb10">'
							+'<div style="width:88px;height:88px;flex-shrink: 0;">'
								+'<img src="'+getBaseImgUrl(projectimage)+'" class="db w100 h100">'
							+'</div>'
							+'<div class="mgl3" style="flex-grow: 2;">'
								+'<h4 class="c3 f15">'+obj.projectname+'</h4>'
								+'<p class="c9 f12 mgt10">'+obj.ctimeAbout+'</p>'
								+'<div class="flexBox f16 mgt10">'
									+'<p class="c6">&times;'+obj.ordernum+'</p>'
									+'<p class="orange">&yen;'+obj.totalrmb+'</p>'
								+'</div>'
							+'</div>'
						+'</div>'
					+'</section>';
    	});
    	 $("#resText").after(htmlStr);
    }
    
    
    
    function toOrderDetail(orderid) {
        window.location.href = 'mb/jsp/zhongchouOrderDetail.jsp?orderid=' + orderid;
    }
    
   
    $(document).ready(function(){
    
    
		getData();
		
		
		$(window).scroll(function () {
	        if ($(window).scrollTop() == $(document).height() - $(window).height()) {
		           if (curpageVal < total) {
		               curpageVal++;
		                $("#loading").slideDown();
		               getData();
		               $("#loading").slideUp();
	              }
	              else {
		               	$("#loadingComplete").slideDown();
		               	var close = function (){
		               	  $("#loadingComplete").slideUp()
		               	};
		   				setTimeout(close,3000);
		   				clearTimeout(close); 
		   				return false;
	              } 
	              
	        }
	 
	    });
	    
	    
	      //选择类型
        $(".kindNav>div>span").click(function () {
            var kindNameOld = $(".kindNavCurrent").text();
            var kindNameNow = $(this).text();

            if (kindNameOld != kindNameNow) {
                $(".kindNav>div>span").removeClass('kindNavCurrent');
                $(this).addClass('kindNavCurrent');
                
				/* 类型， -1:全部 0:已取消 1：待付款 2：待发货 5：待收货 6：已完成 */
				if(kindNameNow=="全部"){
					typeVal = -1;
				}else if(kindNameNow=="待付款"){
					typeVal = 1;
				}else if(kindNameNow=="待发货"){
					typeVal = 2;
				}else if(kindNameNow=="待收货"){
					typeVal = 5;
				}else if(kindNameNow=="已完成"){
					typeVal = 6;
				}
                curpageVal = 1;
                $("#container").html('<div id="resText"></div><!--resText-->');
                htmlStr = "";
                console.log("clear");
                
                getData();
            }

        });
        
        
	});
</script>

</body>
</html>
